package cn.com.bo.util.tools;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Random;

public class ToolsForNumber {
    
	
	/**
	 * 返回1到99的随机数
	 * @return
	 */
	public static int getRandomNumber(){
		Random rdm = new Random(System.currentTimeMillis());
		return Math.abs(rdm.nextInt()) % 100;
	}

	/**
	 * 获取指定float的四舍五入
	 * @param data 数字
	 * @param num 保留位数
	 * @return
	 */
	public static String  format(float data, int num) {
		// float data = 0.03458465165165f;
		NumberFormat famatter = NumberFormat.getNumberInstance(java.util.Locale.CHINA);
		famatter.setMaximumFractionDigits(num);
		String sData = famatter.format(data).replaceAll(",", "");
		return sData;
	}
	
	public static String format(double data,String pattern){
	    DecimalFormat df=new DecimalFormat(pattern);
	    return df.format(data);
	}
	
	public static String format(double data, int num) {
        NumberFormat famatter = NumberFormat.getNumberInstance(java.util.Locale.CHINA);
        famatter.setMaximumFractionDigits(num);
        String sData = famatter.format(data).replaceAll(",", "");
        return sData;
    }
	
	public static  Double toFixed(Double data, int num){
	    NumberFormat famatter = NumberFormat.getNumberInstance(java.util.Locale.CHINA);
        famatter.setMaximumFractionDigits(num);
        String sData = famatter.format(data).replaceAll(",", "");
        return Double.parseDouble(sData);
	}
	
	
	public static void main(String[] args)
    {
    }
}
